Offline Maps

MGLOfflineRegion

@protocol MGLOfflineRegion <NSObject>

An object conforming to the MGLOfflineRegion protocol determines which resources are required by an MGLOfflinePack object.

  • styleURL

    URL of the style whose resources are required for offline viewing.

    In addition to the JSON stylesheet, different styles may require different font glyphs, sprite sheets, and other resources.

    The URL may be a full HTTP or HTTPS URL or a canonical URL

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSURL *_Nonnull styleURL;

    Swift

    var styleURL: URL { get }
  • includesIdeographicGlyphs

    Specifies whether to include ideographic glyphs in downloaded font data. Ideographic glyphs make up the majority of downloaded font data, but it is possible to configure the renderer to use locally installed fonts instead of relying on fonts downloaded as part of the offline pack. See MGLIdeographicFontFamilyName setting. Also, for regions outside of China, Japan, and Korea, these glyphs will rarely appear for non-CJK users.

    By default, this property is set to NO, so that the offline pack will include ideographic glyphs.

    Declaration

    Objective-C

    @property (nonatomic) BOOL includesIdeographicGlyphs;

    Swift

    var includesIdeographicGlyphs: Bool { get set }

MGLOfflineStorage


          @interface MGLOfflineStorage : NSObject

MGLOfflineStorage implements a singleton (shared object) that manages offline packs and ambient caching. All of this class’s instance methods are asynchronous, reflecting the fact that offline resources are stored in a database. The shared object maintains a canonical collection of offline packs in its packs property.

Mapbox resources downloaded via this API are subject to separate Vector Tile and Raster Tile API pricing and are not included in the Maps SDK’s “unlimited” requests. See our pricing page for more information.

See the Download an offline map example to learn how to create and register an offline pack for a defined region.

  • sharedOfflineStorage

    Returns the shared offline storage object.

    Declaration

    Objective-C

    @property (class, nonatomic, readonly) MGLOfflineStorage *_Nonnull sharedOfflineStorage;

    Swift

    class var shared: MGLOfflineStorage { get }

Accessing the Delegate

  • delegate

    The receiver’s delegate.

    An offline storage object sends messages to its delegate to allow it to transform URLs before they are requested from the internet. This can be used add or remove custom parameters, or reroute certain requests to other servers or endpoints.

    Declaration

    Objective-C

    @property (nonatomic, weak, nullable) id<MGLOfflineStorageDelegate> delegate;

    Swift

    @IBOutlet weak var delegate: MGLOfflineStorageDelegate? { get set }

Managing the Database of Offline Packs

  • databasePath

    The file path at which offline packs and the ambient cache are stored.

    To customize this path, specify the MGLOfflineStorageDatabasePath key in Info.plist.

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NSString *_Nonnull databasePath;

    Swift

    var databasePath: String { get }
  • databaseURL

    The file URL at which offline packs and the ambient cache are stored.

    To customize this path, specify the MGLOfflineStorageDatabasePath key in Info.plist.

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NSURL *_Nonnull databaseURL;

    Swift

    var databaseURL: URL { get }
  • -addContentsOfFile:withCompletionHandler:

    Adds the offline packs located at the given file path to offline storage.

    The file must be a valid offline pack database bundled with the application or downloaded separately.

    The resulting packs are added or updated to the shared offline storage object’s packs property, then the completion block is executed.

    Declaration

    Objective-C

    - (void)addContentsOfFile:(nonnull NSString *)filePath
                  withCompletionHandler:
                      (nullable MGLBatchedOfflinePackAdditionCompletionHandler)completion;

    Swift

    func addContents(ofFile filePath: String) async throws -> (URL, [MGLOfflinePack])

    Parameters

    filePath

    A string representation of the file path. The file path must be writable as schema updates may be perfomed.

    completion

    The completion handler to call once the contents of the given file has been added to offline storage. This handler is executed asynchronously on the main queue.

  • -addContentsOfURL:withCompletionHandler:

    Adds the offline packs located at the given URL to offline storage.

    The file must be a valid offline pack database bundled with the application or downloaded separately.

    The resulting packs are added or updated to the shared offline storage object’s packs property, then the completion block is executed.

    Declaration

    Objective-C

    - (void)addContentsOfURL:(nonnull NSURL *)fileURL
                  withCompletionHandler:
                      (nullable MGLBatchedOfflinePackAdditionCompletionHandler)completion;

    Swift

    func addContents(of fileURL: URL) async throws -> (URL, [MGLOfflinePack])

    Parameters

    fileURL

    A file URL specifying the file to add. The URL should be a valid system path. The URL must be writable as schema updates may be performed.

    completion

    The completion handler to call once the contents of the given file has been added to offline storage. This handler is executed asynchronously on the main queue.

Managing Offline Packs

  • packs

    An array of all known offline packs, in the order in which they were created.

    This property is set to nil, indicating that the receiver does not yet know the existing packs, for an undefined amount of time starting from the moment the shared offline storage object is initialized until the packs are fetched from the database. After that point, this property is always non-nil, but it may be empty to indicate that no packs are present.

    To detect when the shared offline storage object has finished loading its packs property, observe KVO change notifications on the packs key path. The initial load results in an NSKeyValueChangeSetting change.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly, nullable) NSArray<MGLOfflinePack *> *packs;

    Swift

    var packs: [MGLOfflinePack]? { get }
  • -addPackForRegion:withContext:completionHandler:

    Creates and registers an offline pack that downloads the resources needed to use the given region offline.

    The resulting pack is added to the shared offline storage object’s packs property, then the completion block is executed with that pack passed in.

    The pack has an initial state of MGLOfflinePackStateInactive. To begin downloading resources, call -[MGLOfflinePack resume] on the pack from within the completion handler. To monitor download progress, add an observer for MGLOfflinePackProgressChangedNotifications about that pack.

    To detect when any call to this method results in a new pack, observe KVO change notifications on the shared offline storage object’s packs key path. Additions to that array result in an NSKeyValueChangeInsertion change.

    Declaration

    Objective-C

    - (void)addPackForRegion:(nonnull id<MGLOfflineRegion>)region
                           withContext:(nonnull NSData *)context
                     completionHandler:
                         (nullable MGLOfflinePackAdditionCompletionHandler)completion;

    Parameters

    region

    A region to download.

    context

    Arbitrary data to store alongside the downloaded resources.

    completion

    The completion handler to call once the pack has been added. This handler is executed asynchronously on the main queue.

  • -removePack:withCompletionHandler:

    Unregisters the given offline pack and allows resources that are no longer required by any remaining packs to be potentially freed.

    As soon as this method is called on a pack, the pack becomes invalid; any attempt to send it a message will result in an exception being thrown. If an error occurs and the pack cannot be removed, do not attempt to reuse the pack object. Instead, if you need continued access to the pack, suspend all packs and use the -reloadPacks method to obtain valid pointers to all the packs.

    To detect when any call to this method results in a pack being removed, observe KVO change notifications on the shared offline storage object’s packs key path. Removals from that array result in an NSKeyValueChangeRemoval change.

    When you remove an offline pack, any resources that are required by that pack, but not other packs, become eligible for deletion from offline storage. Because the backing store used for offline storage is also used as a general purpose cache for map resources, such resources may not be immediately removed if the implementation determines that they remain useful for general performance of the map.

    Declaration

    Objective-C

    - (void)removePack:(nonnull MGLOfflinePack *)pack
                  withCompletionHandler:
                      (nullable MGLOfflinePackRemovalCompletionHandler)completion;

    Swift

    func removePack(_ pack: MGLOfflinePack) async throws

    Parameters

    pack

    The offline pack to remove.

    completion

    The completion handler to call once the pack has been removed. This handler is executed asynchronously on the main queue.

  • -invalidatePack:withCompletionHandler:

    Invalidates the specified offline pack. This method checks that the tiles in the specified offline pack match those from the server. Local tiles that do not match the latest version on the server are updated.

    This is more efficient than deleting the offline pack and downloading it again. If the data stored locally matches that on the server, new data will not be downloaded.

    Declaration

    Objective-C

    - (void)invalidatePack:(nonnull MGLOfflinePack *)pack
                  withCompletionHandler:(nonnull void (^)(NSError *_Nullable))completion;

    Swift

    func invalidatePack(_ pack: MGLOfflinePack) async throws

    Parameters

    pack

    The offline pack to be invalidated.

    completion

    The completion handler to call once the pack has been removed. This handler is executed asynchronously on the main queue.

  • -reloadPacks

    Forcibly, asynchronously reloads the packs property. At some point after this method is called, the pointer values of the MGLOfflinePack objects in the packs property change, even if the underlying data for these packs has not changed. If this method is called while a pack is actively downloading, the behavior is undefined.

    You typically do not need to call this method.

    To detect when the shared offline storage object has finished reloading its packs property, observe KVO change notifications on the packs key path. A reload results in an NSKeyValueChangeSetting change.

    Declaration

    Objective-C

    - (void)reloadPacks;

    Swift

    func reloadPacks()
  • -setMaximumAllowedMapboxTiles:

    Sets the maximum number of Mapbox-hosted tiles that may be downloaded and stored on the current device.

    Once this limit is reached, an MGLOfflinePackMaximumMapboxTilesReachedNotification is posted for every attempt to download additional tiles until already downloaded tiles are removed by calling the -removePack:withCompletionHandler: method.

    Declaration

    Objective-C

    - (void)setMaximumAllowedMapboxTiles:(uint64_t)maximumCount;

    Swift

    func setMaximumAllowedMapboxTiles(_ maximumCount: UInt64)

    Parameters

    maximumCount

    The maximum number of tiles allowed to be downloaded.

  • countOfBytesCompleted

    The cumulative size, measured in bytes, of all downloaded resources on disk.

    The returned value includes all resources, including tiles, whether downloaded as part of an offline pack or due to caching during normal use of MGLMapView.

    Declaration

    Objective-C

    @property (nonatomic, readonly) unsigned long long countOfBytesCompleted;

    Swift

    var countOfBytesCompleted: UInt64 { get }

Managing the Ambient Cache

  • -setMaximumAmbientCacheSize:withCompletionHandler:

    Sets the maximum ambient cache size in bytes. The default maximum cache size is 50 MB. To disable ambient caching, set the maximum ambient cache size to 0. Setting the maximum ambient cache size does not impact the maximum size of offline packs.

    This method does not limit the space available to offline packs, and data in offline packs does not count towards this limit. If you set the maximum ambient cache size to 30 MB then download 20 MB of offline packs, 30 MB will remain available for the ambient cache.

    This method should be called before the map and map style have been loaded.

    This method is potentially expensive, as the database will trim cached data in order to prevent the ambient cache from being larger than the specified amount.

    Declaration

    Objective-C

    - (void)setMaximumAmbientCacheSize:(NSUInteger)cacheSize
                           withCompletionHandler:
                               (nonnull void (^)(NSError *_Nullable))completion;

    Swift

    func setMaximumAmbientCacheSize(_ cacheSize: UInt) async throws

    Parameters

    cacheSize

    The maximum size in bytes for the ambient cache.

    completion

    The completion handler to call once the maximum ambient cache size has been set. This handler is executed synchronously on the main queue.

  • -invalidateAmbientCacheWithCompletionHandler:

    Invalidates the ambient cache. This method checks that the tiles in the ambient cache match those from the server. If the local tiles do not match those on the server, they are re-downloaded.

    This is recommended over clearing the cache or resetting the database because valid local tiles will not be downloaded again.

    Resources shared with offline packs will not be affected by this method.

    Declaration

    Objective-C

    - (void)invalidateAmbientCacheWithCompletionHandler:
                  (nonnull void (^)(NSError *_Nullable))completion;

    Swift

    func invalidateAmbientCache() async throws

    Parameters

    completion

    The completion handler to call once the ambient cache has been revalidated. This handler is executed asynchronously on the main queue.

  • -clearAmbientCacheWithCompletionHandler:

    Clears the ambient cache by deleting resources. This method does not affect resources shared with offline regions.

    Declaration

    Objective-C

    - (void)clearAmbientCacheWithCompletionHandler:
                  (nonnull void (^)(NSError *_Nullable))completion;

    Swift

    func clearAmbientCache() async throws

    Parameters

    completion

    The completion handler to call once resources from the ambient cache have been cleared. This handler is executed asynchronously on the main queue.

  • -resetDatabaseWithCompletionHandler:

    Deletes the existing database, which includes both the ambient cache and offline packs, then reinitializes it.

    You typically do not need to call this method.

    Declaration

    Objective-C

    - (void)resetDatabaseWithCompletionHandler:
                  (nonnull void (^)(NSError *_Nullable))completion;

    Swift

    func resetDatabase() async throws

    Parameters

    completion

    The completion handler to call once the pack has database has been reset. This handler is executed asynchronously on the main queue.

  • -preloadData:forURL:modificationDate:expirationDate:eTag:mustRevalidate:

    Inserts the provided resource into the ambient cache.

    This method mimics the caching that would take place if the equivalent resource were requested in the process of map rendering. Use this method to pre-warm the cache with resources you know will be requested.

    This method is asynchronous; the data may not be immediately available for in-progress requests, though subsequent requests should have access to the cached data.

    To find out when the resource is ready to retrieve from the cache, use the -preloadData:forURL:modificationDate:expirationDate:eTag:mustRevalidate:completionHandler: method.

    Declaration

    Objective-C

    - (void)preloadData:(nonnull NSData *)data
                            forURL:(nonnull NSURL *)url
                  modificationDate:(nullable NSDate *)modified
                    expirationDate:(nullable NSDate *)expires
                              eTag:(nullable NSString *)eTag
                    mustRevalidate:(BOOL)mustRevalidate;

    Swift

    func preload(_ data: Data, for url: URL, modifiedOn modified: Date?, expiresOn expires: Date?, eTag: String?, mustRevalidate: Bool)

    Parameters

    data

    Response data to store for this resource. The data is expected to be uncompressed; internally, the cache will compress data as necessary.

    url

    The URL at which the data can normally be found.

    modified

    The date the resource was last modified.

    expires

    The date after which the resource is no longer valid.

    eTag

    An HTTP entity tag.

    mustRevalidate

    A Boolean value indicating whether the data is still usable past the expiration date.

  • -preloadData:forURL:modificationDate:expirationDate:eTag:mustRevalidate:completionHandler:

    Inserts the provided resource into the ambient cache, calling a completion handler when finished.

    This method is asynchronous. The data is available for in-progress requests as soon as the completion handler is called.

    This method is asynchronous; the data may not be immediately available for in-progress requests, though subsequent requests should have access to the cached data.

    Declaration

    Objective-C

    - (void)preloadData:(nonnull NSData *)data
                             forURL:(nonnull NSURL *)url
                   modificationDate:(nullable NSDate *)modified
                     expirationDate:(nullable NSDate *)expires
                               eTag:(nullable NSString *)eTag
                     mustRevalidate:(BOOL)mustRevalidate
                  completionHandler:
                      (nullable MGLOfflinePreloadDataCompletionHandler)completion;

    Swift

    func preload(_ data: Data, for url: URL, modificationDate modified: Date?, expirationDate expires: Date?, eTag: String?, mustRevalidate: Bool) async throws -> URL

    Parameters

    data

    Response data to store for this resource. The data is expected to be uncompressed; internally, the cache will compress data as necessary.

    url

    The URL at which the data can normally be found.

    modified

    The date the resource was last modified.

    expires

    The date after which the resource is no longer valid.

    eTag

    An HTTP entity tag.

    mustRevalidate

    A Boolean value indicating whether the data is still usable past the expiration date.

    completion

    The completion handler to call once the data has been preloaded. This handler is executed asynchronously on the main queue.

MGLOfflinePack


          @interface MGLOfflinePack : NSObject

An MGLOfflinePack represents a collection of resources necessary for viewing a region offline to a local database.

To create an instance of MGLOfflinePack, use the +[MGLOfflineStorage addPackForRegion:withContext:completionHandler:] method. A pack created using -[MGLOfflinePack init] is immediately invalid.

Example

MGLOfflineStorage.shared.addPack(for: region, withContext: context) { (pack, error) in
              guard let pack = pack else {
                  // If adding the pack fails, log an error to console.
                  print("Error:", error?.localizedDescription ?? "unknown error adding pack at \(#file)(\(#line)) in \(#function)")
                  return
              }
          
              // Start an MGLOfflinePack download
              pack.resume()
          }
          
  • region

    The region for which the pack manages resources.

    Declaration

    Objective-C

    @property (nonatomic, readonly) id<MGLOfflineRegion> _Nonnull region;

    Swift

    var region: MGLOfflineRegion { get }
  • context

    Arbitrary data stored alongside the downloaded resources.

    The context typically holds application-specific information for identifying the pack, such as a user-selected name.

    To change the value of this property, use the -setContext:completionHandler: method. If you access this property after calling that method but before its completion handler is called, this property’s value may not reflect the new value that you specify.

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSData *_Nonnull context;

    Swift

    var context: Data { get }
  • -setContext:completionHandler:

    Associates arbitrary contextual data with the offline pack, replacing any context that was previously associated with the offline pack.

    Setting the context is asynchronous. The context property may not be updated until the completion handler is called.

    Declaration

    Objective-C

    - (void)setContext:(nonnull NSData *)context
                  completionHandler:(void (^_Nullable)(NSError *_Nullable))completion;

    Swift

    func setContext(_ context: Data) async throws

    Parameters

    context

    The new context to associate with the offline pack.

    completion

    The completion handler to call when the context has been updated. If there is an error setting the context, the error is passed into the completion handler.

  • state

    The pack’s current state.

    The state of an inactive or completed pack is computed lazily and is set to MGLOfflinePackStateUnknown by default. To request the pack’s status, use the -requestProgress method. To get notified when the state becomes known and when it changes, observe KVO change notifications on this pack’s state key path. Alternatively, you can add an observer for MGLOfflinePackProgressChangedNotifications about this pack that come from the default notification center.

    Declaration

    Objective-C

    @property (nonatomic, readonly) MGLOfflinePackState state;

    Swift

    var state: MGLOfflinePackState { get }
  • progress

    The pack’s current progress.

    The progress of an inactive or completed pack is computed lazily, and all its fields are set to 0 by default. To request the pack’s progress, use the -requestProgress method. To get notified when the progress becomes known and when it changes, observe KVO change notifications on this pack’s state key path. Alternatively, you can add an observer for MGLOfflinePackProgressChangedNotifications about this pack that come from the default notification center.

    Declaration

    Objective-C

    @property (nonatomic, readonly) MGLOfflinePackProgress progress;

    Swift

    var progress: MGLOfflinePackProgress { get }
  • -resume

    Resumes downloading if the pack is inactive.

    When a pack resumes after being suspended, it may begin by iterating over the already downloaded resources. As a result, the progress structure’s countOfResourcesCompleted field may revert to 0 before rapidly returning to the level of progress at the time the pack was suspended.

    To temporarily suspend downloading, call the -suspend method.

    Declaration

    Objective-C

    - (void)resume;

    Swift

    func resume()
  • -suspend

    Temporarily stops downloading if the pack is active.

    A pack suspends asynchronously, so some network requests may be sent after this method is called. Regardless, the progress property will not be updated until -resume is called.

    If the pack previously reached a higher level of progress before being suspended, it may wait to suspend until it returns to that level.

    To resume downloading, call the -resume method.

    Declaration

    Objective-C

    - (void)suspend;

    Swift

    func suspend()
  • -requestProgress

    Request an asynchronous update to the pack’s state and progress properties.

    The state and progress of an inactive or completed pack are computed lazily. If you need the state or progress of a pack whose state property is currently set to MGLOfflinePackStateUnknown, observe KVO change notifications on this pack’s state key path, then call this method. Alternatively, you can add an observer for MGLOfflinePackProgressChangedNotification about this pack that come from the default notification center.

    Declaration

    Objective-C

    - (void)requestProgress;

    Swift

    func requestProgress()

MGLOfflinePackProgress

struct MGLOfflinePackProgress {}

A structure containing information about an offline pack’s current download progress.

  • countOfResourcesCompleted

    The number of resources, including tiles, that have been completely downloaded and are ready to use offline.

    Declaration

    Objective-C

    uint64_t countOfResourcesCompleted

    Swift

    var countOfResourcesCompleted: UInt64
  • countOfBytesCompleted

    The cumulative size of the downloaded resources on disk, including tiles, measured in bytes.

    Declaration

    Objective-C

    uint64_t countOfBytesCompleted

    Swift

    var countOfBytesCompleted: UInt64
  • countOfTilesCompleted

    The number of tiles that have been completely downloaded and are ready to use offline.

    Declaration

    Objective-C

    uint64_t countOfTilesCompleted

    Swift

    var countOfTilesCompleted: UInt64
  • countOfTileBytesCompleted

    The cumulative size of the downloaded tiles on disk, measured in bytes.

    Declaration

    Objective-C

    uint64_t countOfTileBytesCompleted

    Swift

    var countOfTileBytesCompleted: UInt64
  • countOfResourcesExpected

    The minimum number of resources that must be downloaded in order to view the pack’s full region without any omissions.

    At the beginning of a download, this count is a lower bound; the number of expected resources may increase as the download progresses.

    Declaration

    Objective-C

    uint64_t countOfResourcesExpected

    Swift

    var countOfResourcesExpected: UInt64
  • maximumResourcesExpected

    The maximum number of resources that must be downloaded in order to view the pack’s full region without any omissions.

    At the beginning of a download, when the exact number of required resources is unknown, this field is set to UINT64_MAX. Thus this count is always an upper bound.

    Declaration

    Objective-C

    uint64_t maximumResourcesExpected

    Swift

    var maximumResourcesExpected: UInt64

MGLOfflinePackState

enum MGLOfflinePackState : NSInteger {}

The state an offline pack is currently in.

MGLTilePyramidOfflineRegion


          @interface MGLTilePyramidOfflineRegion
              : NSObject <MGLOfflineRegion, NSSecureCoding, NSCopying>

An offline region defined by a style URL, geographic coordinate bounds, and range of zoom levels.

To minimize the resources required by an irregularly shaped offline region, use the MGLShapeOfflineRegion class instead.

Example

let northeast = CLLocationCoordinate2D(latitude: 40.989329, longitude: -102.062592)
          let southwest = CLLocationCoordinate2D(latitude: 36.986207, longitude: -109.049896)
          let bbox = MGLCoordinateBounds(sw: southwest, ne: northeast)
          
          let region = MGLTilePyramidOfflineRegion(styleURL: MGLStyle.lightStyleURL, bounds: bbox, fromZoomLevel: 11, toZoomLevel: 14)
          let context = "Tile Pyramid Region".data(using: .utf8)
          MGLOfflineStorage.shared.addPack(for: region, withContext: context!)
          

See the Download an offline map example to learn how to define an offline region to be downloaded to a user’s device.

  • bounds

    The coordinate bounds for the geographic region covered by the downloaded tiles.

    Declaration

    Objective-C

    @property (nonatomic, readonly) MGLCoordinateBounds bounds;

    Swift

    var bounds: MGLCoordinateBounds { get }
  • minimumZoomLevel

    The minimum zoom level for which to download tiles and other resources.

    For more information about zoom levels, -[MGLMapView zoomLevel].

    Declaration

    Objective-C

    @property (nonatomic, readonly) double minimumZoomLevel;

    Swift

    var minimumZoomLevel: Double { get }
  • maximumZoomLevel

    The maximum zoom level for which to download tiles and other resources.

    For more information about zoom levels, -[MGLMapView zoomLevel].

    Declaration

    Objective-C

    @property (nonatomic, readonly) double maximumZoomLevel;

    Swift

    var maximumZoomLevel: Double { get }
  • -initWithStyleURL:bounds:fromZoomLevel:toZoomLevel:

    Initializes a newly created offline region with the given style URL, geographic coordinate bounds, and range of zoom levels.

    This is the designated initializer for MGLTilePyramidOfflineRegion.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithStyleURL:(nullable NSURL *)styleURL
                                                bounds:(MGLCoordinateBounds)bounds
                                         fromZoomLevel:(double)minimumZoomLevel
                                           toZoomLevel:(double)maximumZoomLevel;

    Swift

    init(styleURL: URL?, bounds: MGLCoordinateBounds, fromZoomLevel minimumZoomLevel: Double, toZoomLevel maximumZoomLevel: Double)

    Parameters

    styleURL

    URL of the map style for which to download resources. The URL may be a full HTTP or HTTPS URL or a canonical style URL. Specify nil for the default style. Relative file URLs cannot be used as offline style URLs. To download the online resources required by a local style, specify a URL to an online copy of the style.

    bounds

    The coordinate bounds for the geographic region to be covered by the downloaded tiles.

    minimumZoomLevel

    The minimum zoom level to be covered by the downloaded tiles. This parameter should be set to at least 0 but no greater than the value of the maximumZoomLevel parameter. For each required tile source, if this parameter is set to a value less than the tile source’s minimum zoom level, the download covers zoom levels down to the tile source’s minimum zoom level.

    maximumZoomLevel

    The maximum zoom level to be covered by the downloaded tiles. This parameter should be set to at least the value of the minimumZoomLevel parameter. For each required tile source, if this parameter is set to a value greater than the tile source’s minimum zoom level, the download covers zoom levels up to the tile source’s maximum zoom level.

MGLShapeOfflineRegion


          @interface MGLShapeOfflineRegion
              : NSObject <MGLOfflineRegion, NSSecureCoding, NSCopying>

An offline region defined by a style URL, geographic shape, and range of zoom levels.

Example

var coordinates = [
              CLLocationCoordinate2D(latitude: 45.522585, longitude: -122.685699),
              CLLocationCoordinate2D(latitude: 45.534611, longitude: -122.708873),
              CLLocationCoordinate2D(latitude: 45.530883, longitude: -122.678833)
          ]
          
          let triangle = MGLPolygon(coordinates: &coordinates, count: UInt(coordinates.count))
          let region = MGLShapeOfflineRegion(styleURL: MGLStyle.lightStyleURL, shape: triangle, fromZoomLevel: 11, toZoomLevel: 14)
          let context = "Triangle Region".data(using: .utf8)
          MGLOfflineStorage.shared.addPack(for: region, withContext: context!)
          

This class requires fewer resources than MGLTilePyramidOfflineRegion for irregularly shaped regions.

  • shape

    The shape for the geographic region covered by the downloaded tiles.

    Declaration

    Objective-C

    @property (nonatomic, readonly) MGLShape *_Nonnull shape;

    Swift

    var shape: MGLShape { get }
  • minimumZoomLevel

    The minimum zoom level for which to download tiles and other resources.

    For more information about zoom levels, -[MGLMapView zoomLevel].

    Declaration

    Objective-C

    @property (nonatomic, readonly) double minimumZoomLevel;

    Swift

    var minimumZoomLevel: Double { get }
  • maximumZoomLevel

    The maximum zoom level for which to download tiles and other resources.

    For more information about zoom levels, -[MGLMapView zoomLevel].

    Declaration

    Objective-C

    @property (nonatomic, readonly) double maximumZoomLevel;

    Swift

    var maximumZoomLevel: Double { get }
  • -initWithStyleURL:shape:fromZoomLevel:toZoomLevel:

    Initializes a newly created offline region with the given style URL, geometry, and range of zoom levels.

    This is the designated initializer for MGLShapeOfflineRegion.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithStyleURL:(nullable NSURL *)styleURL
                                                 shape:(nonnull MGLShape *)shape
                                         fromZoomLevel:(double)minimumZoomLevel
                                           toZoomLevel:(double)maximumZoomLevel;

    Swift

    init(styleURL: URL?, shape: MGLShape, fromZoomLevel minimumZoomLevel: Double, toZoomLevel maximumZoomLevel: Double)

    Parameters

    styleURL

    URL of the map style for which to download resources. The URL may be a full HTTP or HTTPS URL or a canonical URL. Specify nil for the default style. Relative file URLs cannot be used as offline style URLs. To download the online resources required by a local style, specify a URL to an online copy of the style.

    shape

    The shape of the geographic region to be covered by the downloaded tiles.

    minimumZoomLevel

    The minimum zoom level to be covered by the downloaded tiles. This parameter should be set to at least 0 but no greater than the value of the maximumZoomLevel parameter. For each required tile source, if this parameter is set to a value less than the tile source’s minimum zoom level, the download covers zoom levels down to the tile source’s minimum zoom level.

    maximumZoomLevel

    The maximum zoom level to be covered by the downloaded tiles. This parameter should be set to at least the value of the minimumZoomLevel parameter. For each required tile source, if this parameter is set to a value greater than the tile source’s minimum zoom level, the download covers zoom levels up to the tile source’s maximum zoom level.